﻿using System;
using System.Linq;
using FluentResourceMapping.AutoMapping;

namespace FluentResourceMapping.Tests.TestDummies
{
    public class TestsConvention : DefaultMemberResourceMappingConvention
    {
        public override System.Reflection.MemberInfo MapsTo(System.Reflection.MemberInfo property)
        {
            Type mappedType = Enumerable.SingleOrDefault<Type>(ResourceTypes,
                                                               o => o.Name == "Resources" + property.DeclaringType.Name);

            if (mappedType == null)
                return null;

            System.Reflection.MemberInfo mappedMember =
                mappedType.GetMembers().SingleOrDefault(m => m.Name == property.Name);

            if (mappedMember == null)
                return null;

            return mappedMember;
        }
    }
}